package com.chzc.fm.duotin.adapter.recyclerview;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.chzc.fm.duotin.R;
import com.chzc.fm.duotin.bean.channel.HotChannel;

import java.util.List;

/**
 * Created by Administrator on 2016/6/28.
 */
public class HotTopAdapter extends RecyclerView.Adapter<HotTopAdapter.HotTopViewHolder> {

    private Context context;
    private LayoutInflater inflater;
    private List<HotChannel> datalist;

    private boolean mark = true;

    private mItemOnClickListener itemOnClickListener;

    public HotTopAdapter(Context context, List<HotChannel> datalist) {
        this.context = context;
        this.datalist = datalist;

        inflater = LayoutInflater.from(context);
    }

    public void setItemOnClickListener(mItemOnClickListener itemOnClickListener)
    {
        this.itemOnClickListener = itemOnClickListener;
    }

    @Override
    public HotTopViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {

        View itemView = inflater.inflate(R.layout.adapter_hot_top,null);
        return new HotTopViewHolder(itemView);
    }

    @Override
    public void onBindViewHolder(HotTopViewHolder holder, final int position) {

        if (position == 0 && mark)
        {
            holder.textView.setSelected(true);
            mark = false;
        }

        holder.itemView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                itemOnClickListener.OnItemClick(position);
            }
        });
        HotChannel hotChannel = datalist.get(position);
        holder.textView.setText(hotChannel.getTitle());
    }

    @Override
    public int getItemCount() {
        return datalist == null ? 0 : datalist.size();
    }

    public class HotTopViewHolder extends RecyclerView.ViewHolder {

        TextView textView;

        public HotTopViewHolder(View itemView) {
            super(itemView);

            textView = (TextView) itemView.findViewById(R.id.adaptet_hot_top_tv);
        }
    }
    public interface mItemOnClickListener
    {
        void OnItemClick(int position);
    }
}
